--[[ 编码: WMS-16-09 名称: 盘点计划-查询面板-确定后 作者:HAN 日期:2025-1-29 级别:固定 (说明本段代码在项目中不太会变化) 函数: ClickOK 功能: -- 获取查面板中输入的 盘点类型,仓库,库区等信息 -- 货位 result_grid中选择的数据对象 更改记录: V2.0 HAN 20250212 -- 因为增加“全选”,改进了程序结构 --]] wms_count = require( "wms_count" ) wms_wh = require( "wms_wh" ) local function create_cp_good( strLuaDEID, count_plan, obj ) local nRet, strRetInfo local cp_good = m3.AllocObject(strLuaDEID,"CP_Good_List") cp_good.cp_no = count_plan.cp_no cp_good.item_code = obj.item_code cp_good.item_name = obj.item_name cp_good.qty = obj.qty -- check -- 判断一下查询结果 Grid 中设置的 属性 是否足够支撑创建 CP_Good_List if ( obj.item_code == nil) then return 2, "数据类标识 = "..result_cls_id.." 的选择结果Grid中没有定义 S_ITEM_CODE 属性" end if ( obj.item_name == nil) then return 2, "数据类标识 = "..result_cls_id.." 的选择结果Grid中没有定义 S_ITEM_NAME 属性" end if ( obj.qty == nil) then return 2, "数据类标识 = "..result_cls_id.." 的选择结果Grid中没有定义 F_QTY 属性" end nRet, cp_good = m3.CreateDataObj( strLuaDEID, cp_good ) if (nRet ~= 0) then return 2, cp_good end return 0 end local function create_cp_location( strLuaDEID, count_plan, obj ) local nRet, strRetInfo, loc nRet, loc = wms_wh.GetLocInfo( obj.code) if ( nRet ~= 0 ) then return 2, "WMS_GetLocInfo失败! "..loc end local cp_location = m3.AllocObject(strLuaDEID,"CP_Location_List") cp_location.cp_no = count_plan.cp_no cp_location.loc_code = obj.code cp_location.wh_code = loc.wh_code cp_location.area_code = loc.area_code -- check -- 判断一下查询结果 Grid 中设置的 属性 是否足够支撑创建 CP_Good_List if ( obj.code == nil) then return 2, "数据类标识 = "..result_cls_id.." 的选择结果Grid中没有定义 S_CODE 属性" end nRet, cp_location = m3.CreateDataObj( strLuaDEID, cp_location ) if (nRet ~= 0) then return 2, cp_location end return 0 end local function create_cp_count_cntr( strLuaDEID, count_plan, obj ) local nRet, strRetInfo local cp_count_cntr = m3.AllocObject( strLuaDEID, "CP_Count_Container" ) cp_count_cntr.cp_no = count_plan.cp_no cp_count_cntr.cntr_code = obj.code nRet, cp_count_cntr = m3.CreateDataObj( strLuaDEID, cp_count_cntr ) if (nRet ~= 0) then return 2, cp_count_cntr end return 0 end function ClickOK ( strLuaDEID ) local nRet, strRetInfo local area_code -- 获取 库区编码,盘点类型 nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_AREA_CODE", "N_TYPE", "S_WH_CODE", "SelectAll" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end local obj_attrs = json.decode( strRetInfo ) local area_code = lua.Get_StrAttrValue( obj_attrs[1].value ) local count_type = lua.Get_NumAttrValue( obj_attrs[2].value ) local wh_code = lua.Get_StrAttrValue( obj_attrs[3].value ) -- 根据 盘点类型 来创建盘点计划的主表和 盘点货品/盘点容器 local count_plan = m3.AllocObject(strLuaDEID,"Count_Plan") count_plan.type = count_type count_plan.wh_code = wh_code count_plan.area_code = area_code nRet, count_plan = m3.CreateDataObj( strLuaDEID, count_plan ) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), count_plan ) end local obj local result_cls_id = "" -- V2.0 local select_all = lua.Get_StrAttrValue( obj_attrs[4].value ) -- 如果是全选需要根据查询条件来获取选择结果,而不是通过面板中的选择结果面板 if ( select_all == "全选" ) then local strCondition nRet, strCondition = wms_count.Get_CountPlan_QueryPanel_Condition( strLuaDEID, false ) if ( nRet == 1 ) then mobox.setInfo( strLuaDEID, strCondition ) return end if ( nRet > 1 ) then mobox.stopProgram( strLuaDEID, strCondition ) return end -- 根据盘点类型及返回的strCondition查询数据对象 if ( count_type == wms_base.Get_nConst(strLuaDEID, "盘点类型-货品盘点")) then if ( area_code == '' ) then result_cls_id = "WH_Inventory" else result_cls_id = "AZ_Inventory" end elseif ( count_type == wms_base.Get_nConst(strLuaDEID, "盘点类型-货位盘点")) then result_cls_id = "Location" else result_cls_id = "Container" end -- 查询(要支持分页查询) nRet, strRetInfo = mobox.queryDataObjAttr2( strLuaDEID, result_cls_id, strCondition, "", 100 ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "查询'"..result_cls_id.."'数据失败!"..strRetInfo) end if ( strRetInfo ~= '' ) then local queryInfo = json.decode(strRetInfo) local queryID = queryInfo.queryID local nPageCount = queryInfo.pageCount local nPage = 1 local dataSet = queryInfo.dataSet while (nPage <= nPageCount) do strChgItem = '' for n = 1, #dataSet do nRet, obj = m3.ObjAttrStrToLuaObj( result_cls_id, lua.table2str(dataSet[n].attrs) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "m3.ObjAttrStrToLuaObj 失败! "..obj ) end if ( count_type == wms_base.Get_nConst(strLuaDEID, "盘点类型-货品盘点")) then nRet, strRetInfo = create_cp_good( strLuaDEID, count_plan, obj ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_good 失败! "..strRetInfo ) end elseif ( count_type == wms_base.Get_nConst(strLuaDEID, "盘点类型-货位盘点")) then nRet, strRetInfo = create_cp_location( strLuaDEID, count_plan, obj ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_location 失败! "..strRetInfo ) end else nRet, strRetInfo = create_cp_count_cntr( strLuaDEID, count_plan, obj ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_count_cntr 失败! "..strRetInfo ) end end end nPage = nPage + 1 if ( nPage <= nPageCount ) then -- 取下一页 nRet, strRetInfo = mobox.queryDataObjAttr2( queryID, nPage) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "查询【库区量表】失败! nPage="..nPage.." "..strRetInfo ) end queryInfo = json.decode(strRetInfo) dataSet = queryInfo.dataSet end end else mobox.stopProgram( strLuaDEID, "在创建盘点计划前,必须选中要盘点的对象!") return end else -- 获取选择结果 local result_obj nRet, result_obj = m3.GetSysDataJson( strLuaDEID ) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), result_obj ) end local n, nCount nCount = #result_obj if ( nCount == 0 ) then mobox.stopProgram( strLuaDEID, "在创建盘点计划前,必须选中要盘点的对象!") return end if ( count_type == wms_base.Get_nConst(strLuaDEID,"盘点类型-货品盘点")) then -- 创建【计划盘点货品】 if ( area_code == '' ) then result_cls_id = "WH_Inventory" else result_cls_id = "AZ_Inventory" end for n = 1, nCount do nRet, obj = m3.ObjAttrStrToLuaObj( result_cls_id, lua.table2str(result_obj[n].attrs) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "m3.ObjAttrStrToLuaObj 失败! "..obj ) end nRet, strRetInfo = create_cp_good( strLuaDEID, count_plan, obj ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_good 失败! "..strRetInfo ) end end elseif ( count_type == wms_base.Get_nConst(strLuaDEID,"盘点类型-货位盘点")) then -- 创建【计划盘点货位】 result_cls_id = "Location" for n = 1, nCount do nRet, obj = m3.ObjAttrStrToLuaObj( result_cls_id, lua.table2str(result_obj[n].attrs) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "m3.ObjAttrStrToLuaObj 失败! "..obj ) end nRet, strRetInfo = create_cp_location( strLuaDEID, count_plan, obj ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_location 失败! "..strRetInfo ) end end else -- V2.0 容器盘点 -- 创建【计划盘点容器】 result_cls_id = "Container" for n = 1, nCount do nRet, obj = m3.ObjAttrStrToLuaObj( result_cls_id, lua.table2str(result_obj[n].attrs) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "m3.ObjAttrStrToLuaObj 失败! "..obj ) end nRet, strRetInfo = create_cp_count_cntr( strLuaDEID, count_plan, obj ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_count_cntr 失败! "..strRetInfo ) end end end end local action = { { action_type = "refresh", value = "" } } nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction错误: "..strRetInfo) end end